﻿using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Dryricenet
{
    public partial class ph_Order : System.Web.UI.Page
    {
        public int id = 0;
        public string name ="";

        protected void Page_Load(object sender, EventArgs e)
        {
             name = Session["Name"].ToString();
            DataTable dt = userBLL.selectNameBll(name);
            DataRow dr = dt.Rows[0];//第一条数据
            id = Convert.ToInt32(dr["UserID"]);
            if (!IsPostBack)
            {
               
                Refresh(id);
            }
          
        }
        //刷新
        public void Refresh(int id)
        {
            GridView2.DataSource = OrderBLL.orderQTBLL(id);
            GridView2.DataBind();
        }
        //分页
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            Refresh(id);
        }
        //删除

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            int id1 =int.Parse((sender as LinkButton).CssClass);
            OrderDetailsBLL.orderDetailsDeleteBLL(id1);
            OrderBLL.orderDeleteBLL(id1);
            Refresh(id);
        }

        protected void Search_Click(object sender, EventArgs e)
        {
            string sq = "";
            if (drp.Text == "全部")
            {
                Refresh(id);
            }
            if (drp.Text == "订单号")
            {
                sq = "and o.Ordertitle like '%" + TextBox1.Text.Trim() + "%' and o.UserID=" + id;
            }
            if (drp.Text == "姓名")
            {
                sq = "and o.OrderName like '%" + TextBox1.Text.Trim() + "%' and o.UserID=" + id;
            }
            if (drp.Text == "电话")
            {
                sq = "and o.Phone like '%" + TextBox1.Text.Trim() + "%' and o.UserID=" + id;
            }
            if (drp.Text == "是否支付")
            {
                string sf = "";
                if (TextBox1.Text.Trim() == "是")
                {
                    sf = "已付款";
                }
                else
                {
                    sf = "未付款";
                }
                sq = "and o.Zf like '%" + sf + "%' and o.UserID=" + id;
            }
            if (drp.Text == "是否发货")
            {
                string sf = "";
                if (TextBox1.Text.Trim() == "是")
                {
                    sf = "已发货";
                }
                else
                {
                    sf = "未发货";
                }
                sq = "and o.Fh like '%" + sf + "%' and o.UserID=" + id;
            }
            if (drp.Text == "是否收货")
            {
                string sf = "";
                if (TextBox1.Text.Trim() == "是")
                {
                    sf = "已收货";
                }
                else
                {
                    sf = "未收货";
                }
                sq = "and o.Sh like '%" + sf + "%' and o.UserID="+ id;
            }


            GridView2.DataSource = OrderBLL.orderMHBLL(sq);
            GridView2.DataBind();
        }
    }
}